package com.kanshu.ksgb.fastread.doudou.common.view;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;

/**
 * Created by wcy on 2017\7\18 0018.
 */

public class EnableViewPager extends ViewPager {
    private boolean mScrollable = true;
    public EnableViewPager(Context context) {
        super(context);
    }

    public EnableViewPager(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
    public void setScroll(boolean scroll) {
        mScrollable = scroll;
    }
    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        if(this.mScrollable) {
            if (getCurrentItem() == 0 && getChildCount() == 0) {
                return false;
            }
            return super.onTouchEvent(ev);
        } else {
            return false;
        }
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        if(this.mScrollable) {
            if (getCurrentItem() == 0 && getChildCount() == 0) {
                return false;
            }
            return super.onInterceptTouchEvent(ev);
        } else {
            return false;
        }
    }
}
